﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Lyx.Managers
{
    class Graphics
    {
        Tools.SpriteSheet[] spriteSheet = new Tools.SpriteSheet[(int)Tools.ID_SPRITE.END];
        Texture2D square;

        //Fonts
        SpriteFont spriteFont;
        double FPS = 0.0;

        //Load content functions
        public void LoadContent(ContentManager _content)
        {
            square = _content.Load<Texture2D>("debug/square");
            this.spriteFont = _content.Load<SpriteFont>("fonts/SpriteFont1");

            LoadContentSpriteSheet(_content);
        }

        private void LoadContentSpriteSheet(ContentManager _content)
        {
            //Modules
            spriteSheet[(int)Tools.ID_SPRITE.CABIN_DEFAULT] = new Tools.SpriteSheet("ships/cabins/cabin_default/cabin_default", 2, _content);
            spriteSheet[(int)Tools.ID_SPRITE.ENGINE_DEFAULT_LEFT] = new Tools.SpriteSheet("ships/engines/engine_default/engine_default", 3, _content);
            spriteSheet[(int)Tools.ID_SPRITE.ENGINE_DEFAULT_RIGHT] = new Tools.SpriteSheet("ships/engines/engine_default/engine_default", 3, _content);

            //Nature
            spriteSheet[(int)Tools.ID_SPRITE.ASTEROID_ROCK_32] = new Tools.SpriteSheet("nature/asteroids/rock_32/rock_32", 1, _content);

            //Hud
            spriteSheet[(int)Tools.ID_SPRITE.LIMIT_HORIZONTAL] = new Tools.SpriteSheet("hud/limits/limit_horizontal", 1, _content);
            spriteSheet[(int)Tools.ID_SPRITE.LIMIT_VERTICAL] = new Tools.SpriteSheet("hud/limits/limit_vertical", 1, _content);
        }

        //Draw functions
        public void DrawFPS(SpriteBatch _spriteBatch, GameTime _gameTime)
        {
            this.FPS = 1000.0d / _gameTime.ElapsedGameTime.TotalMilliseconds;
            //Formatage de la chaine
            string texte = string.Format("{0:00.00} images / sec", this.FPS);
            //Calcul de la taille de la chaine pour la police de caractère choisie
            Vector2 taille = spriteFont.MeasureString(texte);
            //Affichage de la chaine
            _spriteBatch.DrawString(spriteFont, texte, new Vector2(Tools.Param.WINDOW_WIDTH - taille.X, 5), Color.White);
        }

        public void DrawHUD(SpriteBatch _spriteBatch, int _iNbPlayer)
        {
            if (_iNbPlayer > 1)
            {
                _spriteBatch.Draw(spriteSheet[(int)Tools.ID_SPRITE.LIMIT_VERTICAL].GetImage(0), new Vector2(638.0f, 0.0f), Color.White);

                if (_iNbPlayer > 2)
                {
                    _spriteBatch.Draw(spriteSheet[(int)Tools.ID_SPRITE.LIMIT_HORIZONTAL].GetImage(0), new Vector2(0.0f, 358.0f), Color.White);
                }
            }
        }

        public void DrawUnits(SpriteBatch _spriteBatch, Scene.Map _map)
        {
        }
    }
}
